#include <cstdio>

int m;

long long find( long long p, long long q )
{
    long long left, right, mid;
    left = 1; right = 1 << 30; right *= 2;
    while ( left < right )
    {
        mid = ( left + right ) / 2;
        if ( mid / p - mid / q < m )
            left = mid + 1;
        else
            right = mid;
    }
    return right;
}

int main( )
{
    int t, n;
    long long left, right, mid;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d%d", &n, &m);
        switch( n )
        {
            case 0: printf("%I64d\n", find( 1, 15 )); break;
            case 1: printf("%I64d\n", find( 15, 150 )); break;
            case 2: printf("%I64d\n", find( 150, 750 )); break;
            case 3: printf("%I64d\n", find( 750, 7500 )); break;
            case 4: printf("%I64d\n", find( 7500, 75000 )); break;
            case 5: printf("%I64d\n", find( 75000, 750000 )); break;
            case 6: printf("%I64d\n", find( 750000, 7500000 )); break;
            case 7: printf("%I64d\n", find( 7500000, 75000000 )); break;
            case 8: printf("%I64d\n", find( 75000000, 750000000 )); break;
            case 9: printf("%d\n", 750000000 * m); break;
        }
    }
    return 0;
}
